import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QApplication, QWidget, QVBoxLayout, QHBoxLayout,
                             QPushButton, QLabel, QLineEdit, QFileDialog, QTabWidget, QTextEdit)

# 从 ansys.fluent.core 导入 launch_fluent
# from ansys.fluent.core import launch_fluent  # 调用pyfluent
import os

# 从文件引入
from step1 import MeshTab
from step2 import ProcessTab
from step3 import DisplayTab


class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.session = None
        self.initUI()

    def initUI(self):
        self.resize(800, 600)
        self.setWindowTitle('复杂地形风速仿真模拟')

        # 创建标签页组件
        self.tabs = QTabWidget()
        self.tab1 = MeshTab(self)
        self.tab2 = ProcessTab(self)
        self.tab3 = DisplayTab(self)

        self.tabs.addTab(self.tab1, "第一步：网格划分")
        self.tabs.addTab(self.tab2, "第二步：数据处理")
        self.tabs.addTab(self.tab3, "第三步：结果展示")

        vbox = QVBoxLayout()
        vbox.addWidget(self.tabs)

        # 控制台输出
        consoleOutputLabel = QLabel('控制台输出', self)
        consoleOutputLabel.setAlignment(Qt.AlignCenter)
        self.consoleOutput = QTextEdit(self)
        self.consoleOutput.setFixedHeight(300)
        self.consoleOutput.setReadOnly(True)
        vbox.addWidget(consoleOutputLabel)
        vbox.addWidget(self.consoleOutput)

        self.setLayout(vbox)

       # 引入 QSS 文件
        self.loadStylesheet('style.qss')

    def loadStylesheet(self, filename):
        # 使用绝对路径
        filepath = os.path.join(os.path.dirname(__file__), filename)
        with open(filepath, 'r') as file:
            self.setStyleSheet(file.read())

    def setMeshFile(self, mesh_file):
        self.tab2.setMeshFile(mesh_file)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = MainWindow()
    mainWindow.show()
    sys.exit(app.exec_())
